#ifndef TRIANGULATOR_H
#define TRIANGULATOR_H

#include "point.h"
#include "triangle.h"
#include <vector>
#include <string>
#include <sstream>

using std::vector;
using std::string;

struct triangulator
{
    std::vector<triangle> delaunay_triangulation(const std::vector<point>&);
private:
    int init(const std::vector<point> &) ;
    int localization(int, int) ;
    void create_new_triangles(int, int) ;
    void flip(int, int) ;
    void get_result(std::vector<triangle>&, int) ;
    void check_triangle_and_flip(int t);

    sign is_inside(const triangle&, const point& ) const;
    sign long_in_circle(const triangle&, const point& p) const;
    sign in_circle(const triangle&, const point& ) const;

    int reset(int, int, int);

    string trace_t(int t);

    vector<triangle> tris;
    vector<point> pnts;
    vector<bool> in_triangulation;
    vector<bool> visited;
    vector<int> triangulation_indexes;
};

#endif // TRIANGULATOR_H
